package com.aaa.controller;

import com.aaa.entity.LayData;
import com.aaa.entity.User;
import com.aaa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller
public class LoginController {

    @Autowired
    private UserService userService;
    /**
     * 用户登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    @ResponseBody
    public LayData login(HttpSession session,User user){
        /**
         * 查询该用户是否存在
         */
        LayData layData = new LayData();
        User user1 = userService.login(user);
        if(user1!=null){
            layData.setData(true);
            session.setAttribute("user",user1);
        }
        return layData;
    }
}
